package sanrenxing.dayEnd.backRepertoryTotal.dao;

import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;
import sanrenxing.dayEnd.backRepertoryTotal.domain.CashAccount;
import sanrenxing.dayEnd.backRepertoryTotal.domain.Foundation;
import sanrenxing.dayEnd.backRepertoryTotal.domain.ManagerSetup;
import sanrenxing.dayEnd.backRepertoryTotal.domain.TrusteeSetup;

import java.util.List;
import java.util.Map;

/**
 * 功能：基金数据层接口类
 * 编写者：蒋玲苹
 * 日期：2021-03-12
 * 版本：1.0
 */
@Repository
public interface FoundationDao {
    /**
     * 将基金实体添加数据库基金表中
     * @param foundation 基金对象
     * @return 0:添加失败,1:添加成功
     */
    @Insert("insert into fundSetup values(#{fundId},#{fundName},#{adminId},#{custoId},#{fundType},#{day},to_date('${fundTime}','yyyy-MM-dd'),#{NIF},#{fundSize},#{caId},#{notes})")
    public int add(Foundation foundation);
    /**
     * 从表中根据基金编号删除一行数据
     * @param fundId 基金编号
     * @return 删除影响的行数(0:删除失败,1:删除成功)
     */
    @Delete("delete from fundSetup where fundId='${fundId}'")
    public int delete(@Param("fundId") String fundId);
    /**
     * 修改数据到foundation表
     * @param foundation 员工对象
     * @return 0:修改失败,1:修改成功
     */
    @Update("update fundSetup set fundName=#{fundName},adminId=#{adminId},custoId=#{custoId},fundType=#{fundType},day=#{day},fundTime=to_date('${fundTime}','yyyy-MM-dd')" +
            ",NIF=#{NIF},fundSize=#{fundSize},caId=#{caId},notes=#{notes} where fundId=#{fundId}")
    public int update(Foundation foundation);

    @Select("<script>" +
            "select fundId,fundName,adminId,custoId,fundType,day,to_char(fundTime,'yyyy-MM-dd') as fundTime,NIF,fundSize,caId,notes from " +
            " (select rownum rn,fundSetup.* from fundSetup " +
            " <where>#{end}>=rownum</where>)" +
            "<where>" +
            "<if test='foundation.fundName!=null'>" +
            " and fundName like '%${foundation.fundName}%'" +
            "</if>" +
            "<if test='foundation.fundType!=0'>" +
            " and fundType=#{foundation.fundType}" +
            "</if>" +
            " and rn>=#{start}" +
            "</where>" +
            "</script>")
  /*  @Results({
            @Result(property = "fundId",column = "fundId"),
            @Result(property = "fundName",column = "fundName"),
            @Result(property = "fundComp",column = "adminId"),
            @Result(property = "fundBank",column = "custoId"),
            @Result(property = "fundType",column = "fundType"),
            @Result(property = "day",column = "day"),
            @Result(property = "fundTime",column = "fundTime"),
            @Result(property = "NIF",column = "NIF"),
            @Result(property = "fundSize",column = "fundSize"),
            @Result(property = "caId",column = "caId"),
            @Result(property = "notes",column = "notes"),
    })*/
    public List<Foundation> queryAll(Map<String, Object> map);
    /**
     * 统计记录数
     * @param
     * @return 记录行数据
     */
    @Select("select count(*) from fundSetup")
    public int count();
    @Select("select * from cashAccount")
    public List<CashAccount> ca();
    @Select("select * from managerSetup")
    public List<ManagerSetup> ms();
    @Select("select * from trusteeSetup")
    public List<TrusteeSetup> ts();
}
